unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, RzEdit, Vcl.ExtCtrls,
  RzPanel, RzSplit, FormEx_View, RzButton, UniFieldX;

type
  TForm1 = class(TFormExView)
    RzSplitter1: TRzSplitter;
    Memo_Target: TRzMemo;
    Memo_Source: TRzMemo;
    Tool_1: TRzToolbar;
    Btnv_1: TRzToolButton;
    Btnv_2: TRzToolButton;
    procedure Btnv_1Click(Sender: TObject);
  private
    FListCols: TCollection; //*list of *tunifieldx;
  protected
    procedure SetInitialize;override;
    procedure SetCommParams;override;
    procedure SetGridParams;override;
    procedure SetComboItems;override;
    procedure TryFreeAndNil;override;
  public
  end;

var
  Form1: TForm1;

implementation

uses
  Class_KzUtils,Class_KzDebug;

{$R *.dfm}

procedure TForm1.Btnv_1Click(Sender: TObject);
var
  I: Integer;
  sText: string;
  tText: string;
  cList: TStrings;
  Field: TUniFieldX;
begin
  if FListCols = nil then
  begin
    FListCols := TCollection.Create(TUniFieldX);
  end;
  TKzUtils.JustCleanList(FListCols);

  for I := 0 to Memo_Source.Lines.Count-1 do
  begin
    sText := Memo_Source.Lines.Strings[I];
    if sText = '' then Continue;

    cList := TStringList.Create;
    cList.Delimiter := ' ';
    cList.DelimitedText := sText;

    KzDebug.FileFmt('tablename:%S',[cList.Strings[0]]);
    KzDebug.FileFmt('fieldname:%S',[cList.Strings[1]]);

    Field := TUniFieldX(FListCols.Add);
    Field.TABLNAME := cList.Strings[0];
    Field.COLVNAME := cList.Strings[1];
    Field.TYPENAME := cList.Strings[3];
    Field.DATASIZE := StrToIntDef(cList.Strings[4],0);
  end;

  for I := 0 to FListCols.Count-1 do
  begin
    Field := TUniFieldX(FListCols.Items[I]);
    if Field = nil then Continue;

    Memo_Target.Lines.Add(Format('if not ExistField(%S,%S,ADOConnect) then',[QuotedStr(Field.TABLNAME),QuotedStr(Field.COLVNAME)]));
    Memo_Target.Lines.Add(Format('begin',[]));

    if UpperCase(Field.TYPENAME) = 'VARCHAR' then
    begin
      tText := (Format('ALTER TABLE %S ADD %S VARCHAR(%d) NULL',[(Field.TABLNAME),(Field.COLVNAME),Field.DATASIZE]));
    end else
    begin
      tText := (Format('ALTER TABLE %S ADD %S INT NULL',[(Field.TABLNAME),(Field.COLVNAME)]));
    end;
    Memo_Target.Lines.Add(Format('  ExecuteSQL(%S,ADOConnect);',[QuotedStr(tText)]));
    Memo_Target.Lines.Add(Format('end;',[]));
    Memo_Target.Lines.Add(Format(' ',[]));
  end;
end;

procedure TForm1.SetComboItems;
begin
  inherited;

end;

procedure TForm1.SetCommParams;
begin
  inherited;
  self.RzSplitter1.Percent := 50;
end;

procedure TForm1.SetGridParams;
begin
  inherited;

end;

procedure TForm1.SetInitialize;
begin
  inherited;

end;

procedure TForm1.TryFreeAndNil;
begin
  inherited;

end;

end.
